package com.bestcem.xm.deliver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bestcem.xm.component.mybatis.service.impl.XmServiceImpl;
import com.bestcem.xm.deliver.entity.DeliverDeliver;
import com.bestcem.xm.deliver.entity.DeliverWechatTimingDeliver;
import com.bestcem.xm.deliver.mapper.DeliverWechatTimingDeliverMapper;
import com.bestcem.xm.deliver.service.DeliverWechatTimingDeliverService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.stream.Stream;

import static com.bestcem.xm.deliver.grpc.v1.services.DeliverDelayFailedTtype.DELIVER_DELAY_FAILED_TTYPE_CONTINUE_VALUE;

/**
 * @author been
 * @description 针对表【ds_deliver_wechattimingdeliver】的数据库操作Service实现
 * @createDate 2022-11-07 13:49:47
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class DeliverWechatTimingDeliverServiceImpl extends XmServiceImpl<DeliverWechatTimingDeliverMapper, DeliverWechatTimingDeliver>
        implements DeliverWechatTimingDeliverService {

    @Override
    public boolean checkDeliverStatus(DeliverDeliver deliver) {
        // 好鸡巴弱智，这不是永远返回true吗
        try {
            DeliverWechatTimingDeliver wechat_timing_deliver = baseMapper.selectOne(new QueryWrapper<DeliverWechatTimingDeliver>().lambda()
                    .eq(DeliverWechatTimingDeliver::getDeliverId, deliver.getId())
                    .last("limit 1"));
            if (Stream.of(0).anyMatch(it -> it.equals(wechat_timing_deliver.getTtype()))) {
                return true;
            } else {
                if (deliver.getDelayFailedTtype().equals(DELIVER_DELAY_FAILED_TTYPE_CONTINUE_VALUE)) {
                    return true;
                } else {
                    return true;
                }
            }
        } catch (Exception e) {
            return false;
        }
    }
}




